﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TRPOP.Common;

namespace TRPOP.CMS.Model
{
    /// <summary>
    /// 系统参数模型
    /// </summary>
    [Serializable]
    public class SystemParamInfo
    {
        #region 私有变量
        private string m_ParamName;
        private string m_ParamKey;
        private string m_ParamValue;
        #endregion

        #region 成员函数
        /// <summary>
        /// 参数名称
        /// </summary>
        public string ParamName
        {
            get { return m_ParamName; }
            set { m_ParamName = value; }
        }

        /// <summary>
        /// 参数Key
        /// </summary>
        public string ParamKey
        {
            get { return m_ParamKey; }
            set { m_ParamKey = value; }
        }

        /// <summary>
        /// 参数Value
        /// </summary>
        public string ParamValue
        {
            get { return m_ParamValue; }
            set { m_ParamValue = value; }
        }
        #endregion

        #region 构造器
        public SystemParamInfo()
        {
            m_ParamName = string.Empty;
            m_ParamKey = string.Empty;
            m_ParamValue = string.Empty;
        }
        public SystemParamInfo(string strParamName, string strParamKey, string strParamValue)
        {
            m_ParamName = strParamName;
            m_ParamKey = strParamKey;
            m_ParamValue = strParamValue;
        }
        #endregion
    }
}
/*
/// <summary>
///  获取、设置当前的系统参数信息
/// </summary>
public static class SystemParamHelper
{
    #region 通用方法 构造器 全局变量
    /// <summary>
    /// 根据Key值 获取内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <param name="oList"></param>
    /// <returns></returns>
    static string GetParamByKey(string strKey, List<SystemParamInfo> oList)
    {
        if (oList != null && oList.Count > 0)
        {
            SystemParamInfo oSystemParamInfo = oList.Find(oInfo => oInfo.ParamKey.Equals(strKey, StringComparison.OrdinalIgnoreCase));
            if (oSystemParamInfo != null)
                return oSystemParamInfo.ParamValue;

            return string.Empty;
        }
        else
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// 根据Key值 保存内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <param name="strValue"></param>
    /// <param name="strName"></param>
    /// <param name="oList"></param>
    /// <param name="strFileName"></param>
    /// <returns></returns>
    static bool SetParamByKey(string strKey, string strValue, string strName, List<SystemParamInfo> oList, string strFileName)
    {
        if (oList == null || oList.Count <= 0)
        {
            return false;
        }

        SystemParamInfo oSystemParamInfo = oList.Find(oInfo => oInfo.ParamKey.Equals(strKey, StringComparison.OrdinalIgnoreCase));

        if (oSystemParamInfo == null)
        {
            return false;
        }

        oSystemParamInfo.ParamValue = strValue;
        if (strName != string.Empty)
        {
            oSystemParamInfo.ParamName = strName;
        }

        SerializationHelper.Save(oList, strFileName);

        return true;
    }

    /// <summary>
    /// 初始化参数
    /// </summary>
    /// <param name="oList"></param>
    /// <param name="strFileName"></param>
    /// <param name="GetDefaultParams"></param>
    static List<SystemParamInfo> InitParam(List<SystemParamInfo> oList, string strFileName, Func<List<SystemParamInfo>> GetDefaultParams)
    {
        if (FileUtil.IsExist(strFileName))
        {
            oList = SerializationHelper.Load(typeof(List<SystemParamInfo>), strFileName) as List<SystemParamInfo>;
        }
        if (oList == null || oList.Count <= 0)
        {
            oList = GetDefaultParams();
            SerializationHelper.Save(oList, strFileName);
        }
        return oList;
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    static SystemParamHelper()
    {
        m_MobileFileName = Common.Util.GetMapPath(SystemConst.ConfigRootName + SystemConst.SystemParam_MobileFileName);
        m_AttachmentFileName = Common.Util.GetMapPath(SystemConst.ConfigRootName + SystemConst.SystemParam_AttachmentFileName);
    }

    #endregion

    #region 手机参数
    static string m_MobileFileName;
    static List<SystemParamInfo> m_MobilePrarms;

    /// <summary>
    /// 手机参数信息
    /// </summary>
    public static List<SystemParamInfo> MobilePrarms
    {
        get
        {
            if (m_MobilePrarms == null || m_MobilePrarms.Count <= 0)
            {
                m_MobilePrarms = InitParam(m_MobilePrarms, m_MobileFileName, getDefaultMobileParam);
            }

            return m_MobilePrarms;
        }
        set
        {
            m_MobilePrarms = value;

            if (m_MobilePrarms != null && m_MobilePrarms.Count > 0)
            {
                SerializationHelper.Save(m_MobilePrarms, m_MobileFileName);
            }
        }
    }

    /// <summary>
    /// 根据Key值 获取内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <returns></returns>
    public static string GetMobileParamByKey(string strKey)
    {
        return GetParamByKey(strKey, MobilePrarms);
    }

    /// <summary>
    /// 根据Key值 设置内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <param name="strValue"></param>
    /// <param name="strName"></param>
    /// <returns></returns>
    public static bool SetMobileParamByKey(string strKey, string strValue, string strName)
    {
        return SetParamByKey(strKey, strValue, strName, m_MobilePrarms, m_MobileFileName);
    }

    /// <summary>
    /// 获取默认的手机参数信息
    /// </summary>
    /// <returns></returns>
    static List<SystemParamInfo> getDefaultMobileParam()
    {
        List<SystemParamInfo> oList = new List<SystemParamInfo>();
        oList.Add(new SystemParamInfo("是否开启手机功能", "IsMobile", "1"));
        oList.Add(new SystemParamInfo("手机详细信息页面里图片的最大宽度", "MobileMaxWidth", "300"));
        oList.Add(new SystemParamInfo("手机详细信息页面里图片的最大高度", "MobileMaxHeight", "200"));
        oList.Add(new SystemParamInfo("应用于手机上压缩后的图片的后缀名", "MobileExtName", "_iphone"));
        return oList;
    }
    #endregion

    #region 附件参数
    static string m_AttachmentFileName;
    static List<SystemParamInfo> m_AttachmentPrarms;

    /// <summary>
    /// 附件参数
    /// </summary>
    public static List<SystemParamInfo> AttachmentPrarms
    {
        get
        {
            if (m_AttachmentPrarms == null || m_AttachmentPrarms.Count <= 0)
                m_AttachmentPrarms = InitParam(m_AttachmentPrarms, m_AttachmentFileName, getDefaultAttachmentParam);

            return m_AttachmentPrarms;
        }
        set
        {
            m_AttachmentPrarms = value;

            if (m_AttachmentPrarms != null && m_AttachmentPrarms.Count > 0)
            {
                SerializationHelper.Save(m_AttachmentPrarms, m_AttachmentFileName);
            }
        }
    }

    /// <summary>
    /// 根据Key值 获取内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <returns></returns>
    public static string GetAttachmentParamByKey(string strKey)
    {
        return GetParamByKey(strKey, AttachmentPrarms);
    }

    /// <summary>
    /// 根据Key值 设置内容
    /// </summary>
    /// <param name="strKey"></param>
    /// <param name="strValue"></param>
    /// <param name="strName"></param>
    /// <returns></returns>
    public static bool SetAttachmentParamByKey(string strKey, string strValue, string strName)
    {
        return SetParamByKey(strKey, strValue, strName, m_AttachmentPrarms, m_AttachmentFileName);
    }

    /// <summary>
    /// 获取默认的附件参数信息
    /// </summary>
    /// <returns></returns>
    static List<SystemParamInfo> getDefaultAttachmentParam()
    {
        List<SystemParamInfo> oList = new List<SystemParamInfo>();
        oList.Add(new SystemParamInfo("永久删除结点时，删除发布页面", "defaultdelpage", "True"));
        oList.Add(new SystemParamInfo("永久删除结点或信息时，删除上传图片", "defaultdelimg", "False"));
        oList.Add(new SystemParamInfo("永久删除结点或信息时，删除上传附件", "defaultdelattr", "False"));
        oList.Add(new SystemParamInfo("附件上传_大小限制(K)[最大为10240]", "UpAttachSize", "2048"));
        oList.Add(new SystemParamInfo("图片上传_大小限制(K)[最大为10240]", "UpImageSize", "2048"));
        oList.Add(new SystemParamInfo("图片上传_最大长度(px)[超过则等比缩放]", "UpImageMaxWidth", "600"));
        oList.Add(new SystemParamInfo("图片上传_类型限制", "UpImageType", "jpg|jpeg|png|gif"));
        oList.Add(new SystemParamInfo(" 附件上传_类型限制", "UpAttachType", "zip|rar|doc|xls"));
        oList.Add(new SystemParamInfo("图片压缩_是否留白(反之则剪切图片)", "blnPreserverAspectRatio", "True"));
        oList.Add(new SystemParamInfo("图片上传_压缩列表", "ImgReSave", "100*70,140*105,90*65"));
        oList.Add(new SystemParamInfo("图片上传_命名规则", "UploadFileNameReg", @"Y/md"));
        return oList;
    }
    #endregion
}
*/